package com.prs.crm.service.pm.impl;

import java.io.File;
import java.util.Collection;

import com.prs.crm.context.FileUtil;
import com.prs.crm.context.ToolKits;
import com.prs.crm.dao.pm.PmProjectDao;
import com.prs.crm.domain.Attachment;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.domain.pm.PmGroup;
import com.prs.crm.domain.pm.PmProject;
import com.prs.crm.service.impl.FlowServiceImpl;
import com.prs.crm.service.pm.PmGroupService;
import com.prs.crm.service.pm.PmProjectService;

public class PmProjectServiceImpl extends FlowServiceImpl<PmProject,PmProjectDao> implements PmProjectService{
	private PmGroupService pmGroupService;

	@Override
	public boolean valideSubmit(PmProject pmProject)
	{
		return true;
	}

	@Override
	public void submitProject(PmProject pmProject, File file, String fileName,String memberGroup,String manageGroup) {
		// TODO Auto-generated method stub
		Attachment attach = FileUtil.getInstance().createAttach(file, fileName);
		pmProject.setAttach(attach);		
		
		Collection<Person> managers = this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(manageGroup.split(",")));
//		Collection<Person> members = this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(memberGroup.split(",")));
		Collection<PmGroup> members = this.getPmGroupService().findGroups(ToolKits.convertStringAryToIntAry(memberGroup.split(",")));
		
		pmProject.getMemberGroup().clear();
		pmProject.getManageGroup().clear();
		
		pmProject.getManageGroup().addAll(managers);
		pmProject.getMemberGroup().addAll(members);		
		
		this.save(pmProject);
	}

	public void setPmGroupService(PmGroupService pmGroupService) {
		this.pmGroupService = pmGroupService;
	}

	public PmGroupService getPmGroupService() {
		return pmGroupService;
	}

}
